package website.seamonster.ethegg.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import website.seamonster.ethegg.dataobject.TxReq;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.List;

/**
 * 客户端请求服务
 * Created by 罗海量
 * 2018-07-21 23:25
 */
public interface TxReqRepository extends JpaRepository<TxReq, Long> {
    //根据客户端请求ID找交易请求
    TxReq findFirstByClientIdAndAndCreateTimeBefore(String clientId, Timestamp ts);

    //查找下一条待处理的交易请求
    TxReq findFirstByTxStatusOrderByIdAsc(int txStatus);

    //
    @Query("select sum(r.buyCnt) from TxReq r where r.userId=?1 and r.txStatus=?2")
    Integer getBuyingCountByUserId(String userId, Integer txStatusWait);
}
